package kibahed.interfaces.cards;

public class Card implements Comparable<Card> {

	private ESuite suite;
	private ECardValue cardValue;
	private int value;
	
	public Card() {
		
	}
	
	public Card(ESuite suite, ECardValue cardValue,int value) {
		this.suite = suite;
		this.cardValue = cardValue;
		this.value = value;
	}

	

	public ESuite getSuite() {
		return suite;
	}

	public void setSuite(ESuite suite) {
		this.suite = suite;
	}

	public ECardValue getCardValue() {
		return cardValue;
	}

	public void setCardValue(ECardValue cardValue) {
		this.cardValue = cardValue;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}
	
	public String getTag(String splitter){
		return String.format("%s%s%s", suite,splitter,cardValue);
	}

	@Override
	public int compareTo(Card arg0) {
		
		int i=0;
		switch(suite){
		case HERZ:
			i=100;
			break;
		case KARO:
			i=200;
			break;
		case PIEK:
			i=300;
			break;
		case KREUZ:
			i=400;
		}
		
		i+=value;
		
		int j=0;
		switch(arg0.getSuite()){
		case HERZ:
			j=100;
			break;
		case KARO:
			j=200;
			break;
		case PIEK:
			j=300;
			break;
		case KREUZ:
			j=400;
		}
		
		j+=arg0.getValue();
		
		return (int) Math.signum(i-j);
		
	}

	public String toString() {
		return ""+suite.toString()+"-"+cardValue.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((cardValue == null) ? 0 : cardValue.hashCode());
		result = prime * result + ((suite == null) ? 0 : suite.hashCode());
		result = prime * result + value;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (cardValue != other.cardValue)
			return false;
		if (suite != other.suite)
			return false;
		if (value != other.value)
			return false;
		return true;
	}
}
